package com.tsing.cedap.rest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsing.cedap.rest.entity.CampusEntity;
import com.tsing.cedap.rest.vo.respVo.CampusTreeRespVo;
import com.tsing.cedap.rest.vo.respVo.IdAndNameRespVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 校区表 Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2022-01-26
 */
public interface CampusMapper extends BaseMapper<CampusEntity> {

    @Select("select id,name from cedap_school order by id desc")
    @Result(property = "children", column = "id", many = @Many(select = "getCampusByCid"))
    List<CampusTreeRespVo> campusTree();

    @Select("select id,name from cedap_campus where school_id=#{sId} order by id desc")
    List<IdAndNameRespVo> getCampusByCid(@Param("sId") String id);

    @Select("select u.name,u.id\n" +
            "from cedap_user u\n" +
            "inner join cedap_college c on u.college_id=c.id\n" +
            "inner join cedap_campus ca on c.campus_id=ca.id\n" +
            "where ca.id=#{code} and u.is_rider=2")
    List<IdAndNameRespVo> riderList(@Param("code") String code);

    @Select("SELECT u.name,u.phone id FROM cedap_user u\n" +
            "inner join cedap_college c on c.id=u.college_id\n" +
            "inner join cedap_campus ca on c.campus_id=ca.id\n" +
            " WHERE u.role = 1 and ca.id=#{code} ORDER BY u.update_time DESC")
    List<IdAndNameRespVo> adminPhoneList(@Param("code") String code);

}
